package com.hwj.controller;


import com.hwj.entity.Permission;
import com.hwj.service.PermissionService;
import com.hwj.utils.JsonResponse;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@CrossOrigin
@RequestMapping("/permission")
@Slf4j
public class PermissionController {
    @Autowired
    PermissionService permissionService;

    /*后台分页*/
    @PostMapping("/page")
    public JsonResponse selectAllByPage(@RequestBody(required = false) Permission permission,@RequestParam(value = "pageNum", required = false) Integer pageNum,@RequestParam(value = "pageSize", required = false) Integer pageSize){
        return JsonResponse.successResponse(0,"分页查询权限信息成功",permissionService.page(permission,pageSize,pageNum));
    }

    /*更新*/
    @PutMapping("/")
    public JsonResponse update(@RequestBody Permission permission){
        return JsonResponse.successResponse(0,"更新成功",permissionService.updateByPrimaryKeySelective(permission));
    }

    /*新增*/
    @PostMapping("/")
    public JsonResponse add(@RequestBody Permission permission){
        return JsonResponse.successResponse(0,"新增成功",permissionService.insertSelective(permission));
    }

    /*删除*/
    @DeleteMapping("/{permissionId}")
    public JsonResponse delete(@PathVariable Long permissionId){
        return JsonResponse.successResponse(0,"删除成功",permissionService.deleteByPrimaryKey(permissionId));
    }
}
